//
//  TabbarViewController.m
//  KoreaFlower
//
//  Created by Nicejinux on 12. 11. 10..
//  Copyright (c) 2012년 Nicejinux. All rights reserved.
//

#import "TabbarViewController.h"

@interface TabbarViewController ()

@end

@implementation TabbarViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        //self.tabBar.backgroundColor = [UIColor redColor];
        //self.view.backgroundColor = [UIColor blueColor];
        //self.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar_bg"];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
//    CGRect frame = CGRectMake(0, 0, 320, 49);
//    UIImageView *iv = [[UIImageView alloc] initWithFrame:frame];
//    UIImage *i = [UIImage imageNamed:@"tabBg"];
//    [iv setImage:i];
//    [self.view addSubview:iv];

    //    UIView *v = [[UIView alloc] initWithFrame:frame];
//    UIColor *c = [[UIColor alloc] initWithPatternImage:i];
//    v.backgroundColor = c;
//    [[self tabBar] addSubview:v];
//    self.tabBar.backgroundColor = [UIColor clearColor];
//    [[self tabBar] insertSubview:v atIndex:0];
    
}

- (void)setHidden:(BOOL)hide
{
    self.tabBar.hidden = hide;
    self.view.hidden = hide;
    
    NSLog(@"%f %f %f %f", self.tabBarController.view.frame.origin.x, self.tabBarController.view.frame.origin.y, self.tabBarController.view.frame.size.width, self.tabBarController.view.frame.size.height);
    NSLog(@"%f %f %f %f", self.tabBar.frame.origin.x, self.tabBar.frame.origin.y, self.tabBar.frame.size.width, self.tabBar.frame.size.height);
    
    if (hide) {
        self.view.frame = CGRectMake(0, 480, self.view.frame.size.width, self.view.frame.size.height);
//        self.view.frame = CGRectMake(0, 480, self.tabBar.frame.size.width, self.tabBar.frame.size.height);
    }
    else {
        self.view.frame = CGRectMake(0, 480 - self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
//        self.view.frame = CGRectMake(0, 480 - self.tabBar.frame.size.height, self.tabBar.frame.size.width, self.tabBar.frame.size.height);
    }
//    // Get the tabbar frame
//    CGRect tabbarFrame = self.tabBarController.tabBar.frame;
//    
//    // Create a new rect, to store the size and position
//    CGRect previousTabbarFrame = CGRectMake(tabbarFrame.origin.x, tabbarFrame.origin.y, tabbarFrame.size.width, tabbarFrame.size.height);
//    
//    // Offset to move the tabbar, if we are going from/to fullscreen
//    int offset = !hide ? tabbarFrame.size.height : -1 * tabbarFrame.size.height;
//    
//    // Set tabbar Y position
//    int tabBarY = tabbarFrame.origin.y + offset;
//    tabbarFrame.origin.y = tabBarY;
//    
//    // Set the new tabbar frame
//    self.tabBarController.tabBar.frame = tabbarFrame;
//    
//    // Fade out the tabbar, if we are going to fullscreen. Otherwise, fade it in.
//    self.tabBarController.tabBar.alpha = hide ? 0 : 1;
}

- (void)makeTabBarHidden:(BOOL)hide 
{ 
    // Custom code to hide TabBar 
    if ( [self.tabBarController.view.subviews count] < 2 ) 
    { 
        return; 
    } 
    
    UIView *contentView; 
    
    if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) 
    { 
        contentView = [self.tabBarController.view.subviews objectAtIndex:1]; 
    } 
    else 
    { 
        contentView = [self.tabBarController.view.subviews objectAtIndex:0]; 
    } 
    
    if (hide) 
    { 
        contentView.frame = self.tabBarController.view.bounds; 
    } 
    else 
    { 
        contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x, 
                                       self.tabBarController.view.bounds.origin.y, 
                                       self.tabBarController.view.bounds.size.width, 
                                       self.tabBarController.view.bounds.size.height - self.tabBarController.tabBar.frame.size.height); 
    } 
    self.tabBarController.tabBar.hidden = hide;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
//{
//    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
//}

- (BOOL)shouldAutorotate {
    //    NSLog(@"ios6 회전 shouldAutorotate");
    return NO;
}

- (NSInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    //    NSLog(@"ios other rotate");
    return NO;
}

@end
